import java.util.Random;
import java.util.SimpleTimeZone;

//角色设定
public class Role {
    //角色基础
    private String name;
    private int age;
    private char gender;
    private int blood = 100;
    private String face;
    //角色技能数组
    private String[] kungFu = new String[4];
    //已经获得的技能数
    private int i = 1;

    //构造函数
    public Role() {
    }

    public Role(String name,char gender) {
        this.name = name;
        this.gender = gender;
    }

    //存储外貌的数组
    String[] boyFace = {"英俊潇洒","五官端正","样貌平平","虎背熊腰","面目狰狞"};
    String[] girlFace = {"倾国倾城","小家碧玉","样貌平平","略微简陋","惨不忍睹"};
    //随机姓名数组
    String[] randomName = {"妄仼","刃若","朱武","策善","萨特"};
    //技能数组
    String[] military = {
            "劲拳","飞踢","二连踢","横踢",
            "乌鸦坐飞机","恶龙咆哮","泰山压顶","一叶飞刀","千手观音","无影脚","阴阳指"
    };

    //攻击描述
    String[] attacks_desc = {
            "%s闪到对方身后，使出了%s，朝%s的灵台穴袭去。",
            "%s重心向下使出了%s，朝%s的头部袭去。",
            "%s大喝一声，一招%s朝%s的太阳穴袭去。"
    };

    //受伤描述
    String[] injure_desc = {
            "%s退了半步，还剩%d的血量",
            "%s造成伤痕，还剩%d的血量",
            "%s痛得弯下了腰，还剩%d的血量",
            "%s痛苦闷哼一声，显然受了点内伤，还剩%d的血量",
            "%s摇摇晃晃，明显站不稳了，还剩%d的血量",
            "%s脸色惨白，连退好几步，还剩%d的血量",
            "轰的一声，%s口吐鲜血，还剩%d的血量",
            "%s一声惨叫再也无法站起"
    };

    Random random = new Random();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    //随机姓名
    public void setNameRandom() {
        int index = random.nextInt(randomName.length);
        name = randomName[index];
    }

    public int getAge() {
        return age;
    }

    //随机年龄
    public void setAge() {
        age = random.nextInt(40) + 15;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    public String getFace() {
        return face;
    }

    //随机长相
    public void setFace() {
        if(gender == '男'){
            int index = random.nextInt(boyFace.length);
            face = boyFace[index];
        }else if (gender == '女') {
            int index = random.nextInt(girlFace.length);
            face = girlFace[index];
        }else {
            face = "样貌平平";
        }
    }

    public String[] getKungFu() {
        return kungFu;
    }

    //设置基础技能
    public void setKungFu() {
        kungFu[0] = "直拳";
    }

    //随机技能
    public void setKungFuRandom() {
        int index = random.nextInt(military.length);
        kungFu[i] = military[index];
        i++;
    }

    //攻击
    public void attack(Role role){
        //技能索引
        int index = random.nextInt(i);
        //攻击描述索引
        int attacksDescIndex = random.nextInt(attacks_desc.length);
        System.out.printf(
                attacks_desc[attacksDescIndex],
                this.getName(),
                kungFu[index],
                role.getName()
        );

        int attackBlood = 0;

        //不同攻击技能位，伤害不同
        switch (index){
            case 1 :
                attackBlood = random.nextInt(10) + 5;
                break;
            case 2 :
                attackBlood = random.nextInt(10) + 8;
                break;
            case 3 :
                attackBlood = random.nextInt(10) + 10;
                break;
            case 0 :
                attackBlood = random.nextInt(10);
            default:
                break;
        }

        int remainBlood = role.getBlood() - attackBlood;
        if(remainBlood < 0){
            remainBlood = 0;
        }
        role.setBlood(remainBlood);

        //根据剩余血量判断受伤情况
        if(remainBlood >= 90){
            System.out.printf(
                    injure_desc[0],
                    role.getName(),
                    role.getBlood()
            );
        }else if(remainBlood >= 80 && remainBlood < 90){
            System.out.printf(
                    injure_desc[1],
                    role.getName(),
                    role.getBlood()
            );
        }else if(remainBlood >= 60 && remainBlood < 80){
            System.out.printf(
                    injure_desc[2],
                    role.getName(),
                    role.getBlood()
            );
        }else if(remainBlood >= 40 && remainBlood < 60){
            System.out.printf(
                    injure_desc[3],
                    role.getName(),
                    role.getBlood()
            );
        }else if(remainBlood >= 20 && remainBlood < 40){
            System.out.printf(
                    injure_desc[4],
                    role.getName(),
                    role.getBlood()
            );
        }else if(remainBlood >= 10 && remainBlood < 20){
            System.out.printf(
                    injure_desc[5],
                    role.getName(),
                    role.getBlood()
            );
        }else if(remainBlood > 0 && remainBlood < 10){
            System.out.printf(
                    injure_desc[6],
                    role.getName(),
                    role.getBlood()
            );
        }else {
            System.out.printf(
                    injure_desc[7],
                    role.getName(),
                    role.getBlood()
            );
        }

        System.out.println();
    }
}
